home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’95 / Spy / Offscreen.c < prev    next >
Text File  |  1995-09-10  |  2KB  |  90 lines

  1. /*
  2.  *        Offscreen.c
  3.  */
  4.  
  5.  
  6. #include "Offscreen.h"
  7. //#include "Standard Stuff.h"
  8.  
  9. WindowOffscreen *DrawOffscreen(WindowPtr theWindow, short    rightSlop)
  10.  
  11. {    WindowOffscreen        *theOffscreen;
  12.     GWorldPtr            theWorld;
  13.     short                depth;
  14.     Rect                globalRect;
  15.     OSErr                theErr;
  16.  
  17.     if ((theOffscreen = (WindowOffscreen *) NewPtr(sizeof(WindowOffscreen))) == 0L) {
  18.         return(0L);
  19.     }
  20.     
  21.     SetPort(theWindow);
  22.     GetGWorld(&theOffscreen->windowPort, &theOffscreen->windowDevice);
  23.  
  24.     globalRect = theWindow->portRect;
  25.     LocalToGlobal((Point *) &globalRect.top);
  26.     LocalToGlobal((Point *) &globalRect.bottom);
  27.     globalRect.right += rightSlop;
  28.     
  29.  
  30. //    if((*gPreferences)->useTempMemory) {
  31.         theErr = NewGWorld(&theWorld, 0, &globalRect, 0L, 0L, useTempMem);
  32. //    }
  33. //    else {
  34. //        theErr = NewGWorld(&theWorld, 0, &globalRect, 0L, 0L, 0);
  35. //    }
  36.  
  37.  
  38.     if (theErr == noErr) {
  39.  
  40.         SetGWorld(theWorld, 0L);
  41.         if (! LockPixels(theWorld->portPixMap)) {
  42.             DisposeGWorld(theWorld);
  43.             DisposePtr((Ptr)theOffscreen);
  44.             return(0L);
  45.         }
  46.  
  47.         globalRect = theWorld->portRect;
  48.         globalRect.right -= rightSlop;
  49.         CopyBits(&theWindow->portBits,
  50.                  &((GrafPtr) theWorld)->portBits,
  51.                  &theWindow->portRect,
  52.                  &globalRect,
  53.                  srcCopy, 0L);
  54.  
  55.         theOffscreen->offscreenWorld = theWorld;
  56.         theOffscreen->rightSlop = rightSlop;
  57.         return(theOffscreen);
  58.  
  59.     } else {
  60.  
  61.         DisposePtr((Ptr)theOffscreen);
  62.         return(0L);
  63.  
  64.     }
  65. }
  66.  
  67.  
  68.  
  69.  
  70. void DrawOnscreen(WindowOffscreen *theOffscreen)
  71.  
  72. {
  73.     Rect    copyRect = theOffscreen->offscreenWorld->portRect;
  74.     
  75.     copyRect.right -= theOffscreen->rightSlop;
  76.     if (theOffscreen) {
  77.         SetGWorld(theOffscreen->windowPort, theOffscreen->windowDevice);
  78.         CopyBits(&((GrafPtr) theOffscreen->offscreenWorld)->portBits,
  79.                  (BitMap  *)&(theOffscreen->windowPort)->portPixMap,
  80.                  ©Rect,
  81.                  &theOffscreen->windowPort->portRect,
  82.                  srcCopy, 0L);
  83.         UnlockPixels(theOffscreen->offscreenWorld->portPixMap);
  84.         DisposeGWorld(theOffscreen->offscreenWorld);
  85.         DisposePtr((Ptr) theOffscreen);
  86.     }
  87. }
  88.  
  89.  
  90.